package mood.su.data;

import com.j256.ormlite.field.DatabaseField;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import mood.su.utils.DateUtil;

public class DayMood {
    @DatabaseField(generatedId = true)
    int id;
    @DatabaseField
    private Date date;

    public List<Mood> getMoods() {
        return moods;
    }

    private List<Mood> moods;

    public boolean isDurty() {
        return durty;
    }

    public void setDurty(boolean durty) {
        this.durty = durty;
    }

    private boolean durty;

    /* for ormlite*/
    public DayMood() {

    }

    public DayMood(Date d) {
        date = DateUtil.getDayWithoutHMS(d);
        moods = new ArrayList<Mood>();
        durty = true;
    }

    public boolean isEmpty() {
        return moods.size() == 0;
    }

    public boolean isHappyDay() {
        int happy = 0, sad = 0;

        for (Mood m : moods) {
            if (m.getType() == MoodType.HAPPY) {
                ++happy;
            } else {
                ++sad;
            }
        }

        if (happy > sad) {
            return true;
        } else {
            return false;
        }
    }

    public void addHappyTime() {
        Mood m = new Mood(MoodType.HAPPY, new Date(), null);
        add(m);
    }

    public void addSadTime() {
        Mood m = new Mood(MoodType.BAD, new Date(), null);
        add(m);
    }

    public void add(Mood mood) {
        if(moods == null){
            moods = new ArrayList<Mood>();
        }

        moods.add(mood);
    }

    public int count() {
        if(moods != null) {
            return moods.size();
        }else{
            return 0;
        }
    }

    public Mood get(int pos) {
        if (pos >= 0 && pos < moods.size()) {
            return moods.get(pos);
        } else {
            return null;
        }
    }

    public Date getDate() {
        return date;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
}
